import Cookies from "js-cookie";
const sessionCache = {
  setItem (key, value) {
    if (!sessionStorage) {
      return;
    }
    if (key != null && value != null) {
      sessionStorage.setItem(key, value);
    }
  },
  getItem (key) {
    if (!sessionStorage) {
      return null;
    }
    if (key == null) {
      return null;
    }
    return sessionStorage.getItem(key);
  },
  setJSON (key, jsonValue) {
    if (jsonValue != null) {
      this.setItem(key, JSON.stringify(jsonValue));
    }
  },
  getJSON (key) {
    const value = this.getItem(key);
    if (value != null) {
      return JSON.parse(value);
    }
  },
  removeItem (key) {
    sessionStorage.removeItem(key);
  }
}
const localCache = {
  setItem (key, value) {
    if (!localStorage) {
      return;
    }
    if (key != null && value != null) {
      localStorage.setItem(key, value);
    }
  },
  getItem (key) {
    if (!localStorage) {
      return null;
    }
    if (key == null) {
      return null;
    }
    return localStorage.getItem(key);
  },
  setJSON (key, jsonValue) {
    if (jsonValue != null) {
      this.setItem(key, JSON.stringify(jsonValue));
    }
  },
  getJSON (key) {
    const value = this.getItem(key);
    if (value != null) {
      return JSON.parse(value);
    }
  },
  removeItem (key) {
    localStorage.removeItem(key);
  }
}

export {sessionCache, localCache, Cookies}
